<?php
/**
 * Created by PhpStorm.
 * User: DELL-PC
 * Date: 2018/8/26
 * Time: 20:30
 */

namespace Application\UserCenter\Controller;


use Application\Common\Controller\ElementUITrait;
use J\Intent;
use J\MVC\Controller;


/**
 * ElementUI登录界面
 */
class LoginController extends Controller
{
   use ElementUITrait;

    /**
     * 用户退出界面
     * @param Intent $intent
     */
    protected function optionElementUIExit(Intent $intent)
    {
        $this->getApp()->User()->logout();
        $this->elementUIRedirect($intent, '/element.php/index/index/index', 'App');
    }

    /**
     * 用户登录界面
     * @param Intent $intent
     */
    protected function optionElementUILogin(Intent $intent)
    {
        $intent->value = [
            'view'=>[
                'name'=>'Login',
                'title' => '管理后台',
                'form' => [
                    'url' => '/api.php/UserCenter/Gateway/Login',
                    'fields' => [
                        [
                            'index' => 'user-name',
                            'label' => '用户名',
                            'name' => 'name',
                            'sortable' => true,
                            'rule' => [
                                ['required' => true, 'message' => '请输入用户名', 'trigger' => 'blur']
                            ]
                        ],
                        [
                            'index' => 'user-password',
                            'label' => '密码',
                            'name' => 'password',
                            'holder' => 'password',
                            'rule' => [
                                ['required' => true, 'message' => '请输入密码', 'trigger' => 'blur']
                            ]
                        ],
                        [
                            'index' => 'user-verify',
                            'label' => '验证码',
                            'name' => 'verify',
                            'url' => '/api.php/System/Verify/Index',
                            'holder' => 'verify',
                            'rule' => [
                                ['required' => true, 'message' => '请输入验证码', 'trigger' => 'blur'],
                                [
                                    'validator' => 'validateAsync', 'trigger' => 'blur',
                                    'url' => '/api.php/System/Verify/Check', 'message' => '验证码错误'
                                ]
                            ]
                        ]
                    ],
                ],
            ]
        ];
    }
}